package com.laikan.reader.bookshelf.fragment;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.net.ConnectivityManager;
import android.os.AsyncTask;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.*;
import com.laikan.library.components.BasicApplication;
import com.laikan.library.components.fragments.BasicFragment;
import com.laikan.library.helpers.BasicEvent;
import com.laikan.library.managers.ToastMgr;
import com.laikan.library.utils.DeviceUtil;
import com.laikan.library.utils.SPUtil;
import com.laikan.reader.R;
import com.laikan.reader.apirequester.BookShelfRequester;
import com.laikan.reader.bookfriend.activity.LoginActivity;
import com.laikan.reader.bookfriend.activity.SignInActivity;
import com.laikan.reader.bookreader.activity.ReaderDetailActivity;
import com.laikan.reader.bookshelf.activity.BookManagerActivity;
import com.laikan.reader.bookshelf.activity.BookShelfActivity;
import com.laikan.reader.bookshelf.adapter.BookShelfRecyclerViewAdapter;
import com.laikan.reader.bookstart.activity.HomeActivity;
import com.laikan.reader.core.bean.BaseDataBean;
import com.laikan.reader.core.bean.SignInBean;
import com.laikan.reader.core.events.HomeTabEvent;
import com.laikan.reader.core.events.LaiKanEvent;
import com.laikan.reader.core.interfaces.IResponseActivityEvent;
import com.laikan.reader.core.utils.BookFileUtils;
import com.laikan.reader.core.utils.FileUtil;
import com.laikan.reader.core.utils.PublicUtil;
import com.laikan.reader.core.utils.SystemUtil;
import com.laikan.reader.database.Book;
import com.laikan.reader.database.DBBook;
import com.socks.library.KLog;
import com.umeng.analytics.MobclickAgent;
import org.greenrobot.eventbus.EventBus;

import java.io.File;
import java.util.*;

/**
 * 书架fragment
 * Created by Administrator on 2016/8/8.
 */
public class BookShelfFragment extends BasicFragment implements IResponseActivityEvent {

    private List<Book> mBookListData;       // 缓存书目, 常用书籍数据集合, 收藏书籍数据集合
    private ArrayList<String> mLocalUpdateBookIdList;
    private BookShelfRecyclerViewAdapter mBookShelfAdapter;

    private NetConnectReceiver mNetConnectReceiver;
    // 选中的待删除的book
    private HashSet<String> bookSet = new HashSet<>();
    private Book mBook;

    private SwipeRefreshLayout mBookShelfRefresh;
    private RecyclerView mBookShelfRecyclerView;
    private RelativeLayout mRl_Title;
    private LinearLayout ll_book_data_null;
    private TextView mTV_Back, mTV_BookAll_Selected;
    private ImageView iv_signin_notice;
    private long nexLastClickTime = 0L; // 上一次点击的时间
    public final long INTERVAL = 2500L; // 防止连续点击的时间间隔

    // 常用书籍json文件路径
    private boolean mIsSelectAllItem = false;
    private boolean mIsItemDeleteManager = false;
    private Book mLongPresssDeleteBook;

    @Override
    protected void assignViews() {

        LayoutInflater.from(getActivity()).inflate(R.layout.fragment_book_shelf, mBodyView);
        mTV_BookAll_Selected = (TextView)mBodyView.findViewById(R.id.tv_select_all);
        mTV_Back = (TextView)mBodyView.findViewById(R.id.tv_back_shelf);
        mRl_Title = (RelativeLayout)mBodyView.findViewById(R.id.rl_title);
        mBookShelfRefresh = (SwipeRefreshLayout)mBodyView.findViewById(R.id.store_classify_swiperefresh);
        mBookShelfRefresh.setColorSchemeResources(R.color.C_66ccdd);
        mBookShelfRecyclerView = (RecyclerView)mBodyView.findViewById(R.id.recyclerview_booklist);
        ll_book_data_null = (LinearLayout)mBodyView.findViewById(R.id.ll_book_data_null);
        iv_signin_notice = (ImageView)mBodyView.findViewById(R.id.iv_signin_notice);

        ll_book_data_null.setVisibility(View.GONE);
        mRl_Title.setVisibility(View.GONE);
    }

    @Override
    protected void initData() {
        openEventBus();
        mBookListData = new ArrayList<>();
        mLocalUpdateBookIdList = new ArrayList<>();
        GridLayoutManager gridLayoutManager = new GridLayoutManager(mContext, 3);
        mBookShelfRecyclerView.setLayoutManager(gridLayoutManager);
        mBookShelfAdapter = new BookShelfRecyclerViewAdapter(mContext, mBookListData);
        mBookShelfRecyclerView.setAdapter(mBookShelfAdapter);
        // 1.先从缓存获取数据
        showDialog();
        readCatchBookList();
        if (SystemUtil.isLogin()) {
//            SigninRequester.requestData(mContext, SigninRequester.SIGNIN_REQUEST_BOOKSHELF);
        }

        mNetConnectReceiver = new NetConnectReceiver();
        IntentFilter mFilter = new IntentFilter();
        mFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
        mContext.registerReceiver(mNetConnectReceiver, mFilter);
    }

    /**
     * 从本地获取书架列表数据
     */
    private void readCatchBookList() {
        // 读取书架缓存数据
        ReadAsyncTask readAsyncTask = new ReadAsyncTask();
        readAsyncTask.execute();
    }

    /**
     * 读取缓存记录
     */
    private class ReadAsyncTask extends AsyncTask<Void, Void, List<Book>> {

        @Override
        protected List<Book> doInBackground(Void... strings) {

            mBookListData = BookFileUtils.readCacheBooklist();
            return mBookListData;
        }

        @Override
        protected void onPostExecute(List<Book> mBookListData) {
            super.onPostExecute(mBookListData);
            try {
                // 读取书架缓存数据 初始化ListView数据
                if (mBookShelfRecyclerView != null) {
                    mBookShelfRecyclerView.setFocusable(true);
                    KLog.i("updateDataAdapter from readCatchBookList");
                    updateDataAdapter(mBookListData);
                }
            }catch (NullPointerException e) {
                if (!"".equals(SPUtil.getString("token", ""))) {
                    BookShelfRequester.syncBookFromServer();
                }
            }
        }
    }

    @Override
    protected void setListener() {
        iv_signin_notice.setOnClickListener(this);
        mTV_BookAll_Selected.setOnClickListener(this);
        mTV_Back.setOnClickListener(this);

        mBookShelfRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

            @Override
            public void onRefresh() {
                //开始请求
                BookShelfRequester.syncBookFromServer();
            }
        });

        // 6.设置单击事件处理
        mBookShelfAdapter.setOnItemClickListener(new BookShelfRecyclerViewItemClick());
        // 7.设置长按事件处理
        mBookShelfAdapter.setOnItemLongClickListener(new BookShelfRecyclerViewLongItemClick());
    }

    @Override
    public void onStart() {
        super.onStart();
        KLog.i("life circle onStart");
    }

    @Override
    public void onResume() {
        KLog.i("life circle onResume");
        mBookShelfRefresh.setRefreshing(false);
        //SigninRequester.requestData(mContext, SigninRequester.SIGNIN_REQUEST_BOOKSHELF);

        mBookListData = DBBook.getInstance().queryAllBook();
        updateDataAdapter(mBookListData);

        // 获取预装书信息
        boolean flag = SPUtil.getBoolean("yuZhangBook", true);
        if (flag) {
            String specialBookId = DeviceUtil.getSpecialBookId(mContext, "UMENG_CHANNEL");
            BookShelfRequester.preBook(specialBookId);
        }

        super.onResume();
    }

    @Override
    public void onPause() {
        super.onPause();
        KLog.e("BookShelf  onPause");
    }

    @Override
    public void onStop() {
        super.onStop();
        KLog.e("BookShelf  onStop");
    }

    /**
     * 刷新书架数据
     *
     * @param bookData
     */
    private void updateDataAdapter(List<Book> bookData) {
        dismissDialog();
        mBookShelfAdapter.upDatas(bookData, bookSet);
        KLog.e("bookData : " + bookData.size());
        if (bookData != null && bookData.size() > 0) {
            mBookShelfRefresh.setVisibility(View.VISIBLE);
            mBookShelfRefresh.setEnabled(true);
            ll_book_data_null.setVisibility(View.GONE);
        }else {
            ll_book_data_null.setVisibility(View.VISIBLE);
            mBookShelfRefresh.setVisibility(View.GONE);
            mBookShelfRefresh.setEnabled(false);
        }
    }

    private class BookShelfRecyclerViewItemClick implements BookShelfRecyclerViewAdapter.OnItemClickListener {

        @Override
        public void onItemClick(View view, Object data) {
            if (data instanceof Book) {
                if (mIsItemDeleteManager) {
                    changeSingleItemSelect(view, ((Book)data).getId());
                    if (bookSet.size() == mBookListData.size()) {
                        changeSelectedStatus(false);
                    }else if (bookSet.size() == 0) {
                        changeSelectedStatus(true);
                    }
                }else {  // 单击进入阅读页，先取消单击事件 ，避免重复点击
                    if (bookItem()) {
                        try {
                            mBook = ((Book)data);
                            if (mBook != null) {
                                readChaper(mBook);  //进入阅读页
                            }else {
                                KLog.e("mBook is null.");
                            }
                        }catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                }
            }else {
                if (data instanceof String) {
                    if ((data).equals("add")) {
                        // 跳转精选界面
                        HomeActivity.setCheckById(R.id.radio_bookstore, 1);
                    }
                }
            }

        }
    }

    /**
     * 删除页面通过选中页面的图片是否显示判断，添加删除 书籍
     */
    private void changeSingleItemSelect(View view, String bookid) {
        try {

            ImageView selected = (ImageView)view.findViewById(R.id.selected);
            ImageView select = (ImageView)view.findViewById(R.id.select);
            View shadow = view.findViewById(R.id.shadow);
            if (selected.getVisibility() == View.VISIBLE) {
                // 未选中
                selected.setVisibility(View.GONE);
                select.setVisibility(View.VISIBLE);
                shadow.setVisibility(View.VISIBLE);
                shadow.setBackgroundResource(R.drawable.tv_book_un_select_shadow_bg);
                bookSet.remove(bookid);

            }else if (selected.getVisibility() == View.GONE) {
                // 选中
                select.setVisibility(View.GONE);
                selected.setVisibility(View.VISIBLE);
                shadow.setBackgroundResource(R.drawable.tv_book_selected_shadow_bg);
                bookSet.add(String.valueOf(bookid));
            }
            recordBookDeleete(bookSet.size());
        }catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void recordBookDeleete(int delCount) {
        HomeTabEvent homeTabEvent = new HomeTabEvent();
        homeTabEvent.mIsCoverHomeTab = 2;
        homeTabEvent.RefreshBookDelCount = delCount;
        EventBus.getDefault().post(homeTabEvent);
    }

    /**
     * 控制【下一章按钮】点击频率，即控制点击间隔时间。
     *
     * @return
     */
    public boolean bookItem() {
        long time = System.currentTimeMillis();
        if ((time - nexLastClickTime) > INTERVAL) {
            nexLastClickTime = time;
            return true;
        }
        return false;
    }

    private class BookShelfRecyclerViewLongItemClick implements BookShelfRecyclerViewAdapter.OnItemLongClickListener {

        @Override
        public boolean onLongClick(View view, Object data) {
            MobclickAgent.onEvent(mContext, "sj-sy-ca");//书架-首页-长按
            view.clearFocus();
            if (!mIsItemDeleteManager && data instanceof Book) {
                Intent intent = new Intent();
                intent.setClass(mContext, BookManagerActivity.class);
                intent.putExtra("book", (Book)data);
                mContext.startActivity(intent);
            }
            return true;
        }
    }

    /*
    *处理书架页面与删除页面切换
     */
    private void changeBookShelfPage(boolean deleteManager) {
        if (deleteManager) {
            changeHomeTabDisplay(deleteManager);
            changeActionBarDisplay(deleteManager);
        }else {
            changeHomeTabDisplay(deleteManager);
            changeActionBarDisplay(deleteManager);
        }
    }

    private void changeHomeTabDisplay(boolean isDisplay) {
        HomeTabEvent homeTabEvent = new HomeTabEvent();
        if (isDisplay) {
            homeTabEvent.mIsCoverHomeTab = 0;
        }else {
            homeTabEvent.mIsCoverHomeTab = 1;
        }
        EventBus.getDefault().post(homeTabEvent);
    }

    private void changeActionBarDisplay(boolean ispress) {
        BookShelfActivity ParentActivity = (BookShelfActivity)getActivity();
        if (ispress) {
            ParentActivity.mRL_Tab.setVisibility(View.GONE);
            mRl_Title.setVisibility(View.VISIBLE);
        }else {
            ParentActivity.mRL_Tab.setVisibility(View.VISIBLE);
            mRl_Title.setVisibility(View.GONE);
        }
    }

    @Override
    protected void onClickEvent(View view) {
        switch (view.getId()) {
            case R.id.tv_select_all:
                changeSelectedStatus(mIsSelectAllItem);
                break;
            case R.id.tv_back_shelf:
                backBookShelf();
                break;
            case R.id.iv_signin_notice:
                if (SystemUtil.isLogin()) {
                    Intent intentSign = new Intent(mContext, SignInActivity.class);
                    mContext.startActivity(intentSign);
                }else {
                    mContext.startActivity(new Intent().setClass(mContext, LoginActivity.class));
                }
                break;

            default:
                break;
        }
    }

    /**
     * 删除书籍数量设置
     *
     * @param select true 全选 false 不全选
     */
    private void changeSelectedStatus(boolean select) {
        if (select) {
            // 设置为全选 状态
            mIsSelectAllItem = false;
            selectOrSelectedAll(false);
            mBookShelfAdapter.upDatas(mBookListData, bookSet);
            mTV_BookAll_Selected.setText(R.string.bookshelf_book_select_all);
        }else {
            // 设置为全不选 状态
            mIsSelectAllItem = true;
            selectOrSelectedAll(true);
            mBookShelfAdapter.upDatas(mBookListData, bookSet);
            mTV_BookAll_Selected.setText(R.string.bookshelf_book_select_cancle);
        }
    }

    /**
     * @param isSelectedAll true:全选  false:全不选  // 默认全不选
     */
    private void selectOrSelectedAll(boolean isSelectedAll) {
        if (isSelectedAll) {
            for (int i = 0; i < mBookListData.size(); i++) {   // 全选中
                bookSet.add(mBookListData.get(i).getId());  // 添加到已选中的集合中
            }
        }else {
            bookSet.clear();  // 在选中集合中全部清除
        }
        recordBookDeleete(bookSet.size());
    }

    /**
     * 从删除状态切换到书架控制
     */
    public void backBookShelf() {
        mIsItemDeleteManager = false;
        mBookShelfRefresh.setEnabled(true);
        mIsSelectAllItem = false;
        bookSet.clear();
        mTV_BookAll_Selected.setText(R.string.bookshelf_book_select_all);
        recordBookDeleete(bookSet.size());
        //界面切换
        changeBookShelfPage(mIsItemDeleteManager);
        mBookShelfAdapter.setLongPressStatus(false, (BookShelfActivity)getActivity());

        updateDataAdapter(mBookListData);
    }

    @Override
    protected void parseEvent(BasicEvent event) {
        switch (event.getEventID()) {
            case LaiKanEvent.EVENT_ID_UPDATA_SUCCESS:
                mBookShelfRefresh.setRefreshing(false);
                Map<String, Object> mapEvent = event.getEventMap();
                mBookListData = DBBook.getInstance().queryAllBook();
                if (mBookListData != null) {
                    updateDataAdapter(mBookListData);
                }
                // 更新书籍目录
                if (mapEvent.get("localData") != null) {
                    SaveCacheAsyncTask saveAsyncTask = new SaveCacheAsyncTask();
                    saveAsyncTask.execute((ArrayList<Book>)mapEvent.get("localData"));
                }
                break;
            case LaiKanEvent.EVENT_ID_DISMISS_LOADING:
                mBookShelfRefresh.setRefreshing(false);
                dismissDialog();
                break;
            case LaiKanEvent.EVENT_ID_READ_PRE_BOOK:
                readCatchBookList();
                break;
            case LaiKanEvent.EVENT_ID_LOAD_DIRECTORY:
                // //下载书籍目录通知
                if (mLocalUpdateBookIdList.size() > 0) {
                    DownLoadBookCatalog(mLocalUpdateBookIdList.get(0));
                }
                break;
            case LaiKanEvent.EVENT_ID_BOOK_DELETE_CACHE:
                if (event.getEventAction().equals("from_shlf")) {
                    if (bookSet.size() > 0) {
                        deleteNoticeWindow(null, false);

                    }else {
                        ToastMgr.showShortToast("请选择删除书籍");
                    }
                }
                break;
            case LaiKanEvent.EVENT_ID_BOOKSHELF_DELETE_MANAGER:
                bookDeleteManager();
                break;
            case LaiKanEvent.EVENT_ID_LONGPRESS_CONFIRM:
                mLongPresssDeleteBook = (Book)event.getElves();
                bookSet.add(mLongPresssDeleteBook.getId());
                deleteNoticeWindow(mLongPresssDeleteBook, true);
                break;
            case LaiKanEvent.EVENT_ID_SIGNIN_DATAREQUEST:
                BaseDataBean<SignInBean> result = (BaseDataBean<SignInBean>)event.getElves();
                if (result != null) {
                    int today = Integer.parseInt(result.getData().getTodayWeek()) - 1;
                    if(result.getData().getWeekSigninList().get(today)){
                        KLog.e("bookShelf  true : " + today);
                        iv_signin_notice.setVisibility(View.GONE);
                    }else {
                        KLog.e("bookShelf  false : " + today);
                        //TODO 暂时隐藏 要显示时在打开
//                        iv_signin_notice.setVisibility(View.VISIBLE);
                    }
                }
                break;
            case LaiKanEvent.EVENT_ID_BOOKSHELF_CLOSE_SIGNIN:
                iv_signin_notice.setVisibility(View.GONE);
                break;
            case LaiKanEvent.EVENT_ID_BOOKSHELF_HIDE_EDIT:
                backBookShelf();
                break;
            default:
                break;
        }
    }

    private void bookDeleteManager() {
        // 显示删除操作页面
        // 普通item ， 隐藏父Activity ActionBar, 显示本Fragment Title,Del UI,设置长按状态
        mIsItemDeleteManager = true;
        mBookShelfRefresh.setEnabled(false);
        changeBookShelfPage(mIsItemDeleteManager);
        mBookShelfAdapter.setLongPressStatus(true, (BookShelfActivity)getActivity());
        mBookShelfAdapter.upDatas(mBookListData, bookSet);
        recordBookDeleete(bookSet.size());
    }

    /**
     * 保存更新后书籍列表
     */
    private class SaveCacheAsyncTask extends AsyncTask<ArrayList<Book>, Void, Void> {

        @Override
        protected Void doInBackground(ArrayList<Book>... arg) {
            updateDirectory(arg[0]);
            return null;
        }
    }

    /**
     * 判断mData集合中的书是否有新目录, 有则记录需要下载更新目录的书籍,无则无任何操作
     *
     * @param mData
     */
    private void updateDirectory(ArrayList<Book> mData) {
        for (int i = 0; i < mData.size(); i++) {
            String taskBookId = mData.get(i).getId();
            // 记录要更新目录的书的id
            mLocalUpdateBookIdList.add(taskBookId);
        }
        LaiKanEvent event = LaiKanEvent.getInstance();
        event.setEventID(LaiKanEvent.EVENT_ID_LOAD_DIRECTORY);
        BasicApplication.postEvent(event);
    }

    /**
     * 下载并保存更新后书籍列表,然后删除集合中bookId
     */
    private void DownLoadBookCatalog(String bookid) {
        BookShelfRequester.loadDirectory(bookid);
        mLocalUpdateBookIdList.remove(0);
    }

    /**
     * 删除书籍
     */
    private void removeBooks() {
        // 执行删除选中的书籍
        Iterator<String> it = bookSet.iterator();
        ArrayList<String> delBookList = new ArrayList<>();
        while (it.hasNext()) {
            delBookList.add(it.next());
        }
        BookFileUtils.delLocalBookByIds(delBookList, mBookListData);
        for(String bookid : delBookList){
            File bookContentPath = PublicUtil.getFile(BookFileUtils.BOOKCONTENTPATH + bookid);
            //删除缓存数据
            FileUtil.deleteDir(bookContentPath.getPath());
        }
        // 2.删除该账号服务端的数据
        if (!TextUtils.isEmpty(SPUtil.getString("token", ""))) {
            // 已登录
            it = bookSet.iterator();
            BookShelfRequester.deleteBookData(it);
        }

        // 3.将所有item设置为未选中状态
        selectOrSelectedAll(false);
        bookSet.clear();
        // 4.更新当前的 view
        mBookShelfAdapter.upDatas(mBookListData, bookSet);
    }

    /**
     * 读取该书籍目录,跳转到阅读页 如果本地没有该书籍目录,则重新下载,然后再跳转到阅读页
     *
     * @param b
     */
    private void readChaper(final Book b) {
        Intent intent = new Intent();
        intent.setClass(mContext, ReaderDetailActivity.class);
        intent.putExtra("bookDes", b);
        startActivity(intent);
    }

    @Override
    public void onKeyDown(int keyCode, KeyEvent event) {

    }

    @Override
    public void onKeyUp(int keyCode, KeyEvent event) {
        KLog.e("Bookfragment response");
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        KLog.e("BookShelf  onDestroyView");
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        KLog.e("BookShelf  onDestroy");
    }

    @Override
    public void onActivityResultEvent(int requestCode, int resultCode, Intent data) {
        KLog.i("activity onActivityResult!!!");
    }

    @Override
    public void onPageChangeListener(int position) {
        KLog.e("onPageChangeListener!!!");
    }

    private void deleteNoticeWindow(Book book, final boolean isLongPressDelete) {
        // 一个自定义的布局，作为显示的内容
        View contentView = LayoutInflater.from(mContext).inflate(R.layout.pupwin_delete, null);
        TextView tv_delete_ok = (TextView)contentView.findViewById(R.id.tv_delete_ok);
        TextView tv_delete_cancel = (TextView)contentView.findViewById(R.id.tv_delete_cancel);
        TextView tv_delete_content = (TextView)contentView.findViewById(R.id.tv_delete_content);
        if (book == null) {  //如果book为空，则为标题栏多选删除
            tv_delete_content.setText(R.string.book_shelf_confirm_select_delete);
        }else {
            tv_delete_content.setText(DeviceUtil.getHtmlFormatedString(mContext, R.string.book_shelf_confirm_delete_byname, book.getName()));
        }

        final PopupWindow DeleteNoticepopupWindow = new PopupWindow(contentView,
            LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT, true);

        DeleteNoticepopupWindow.setTouchable(true);
        DeleteNoticepopupWindow.setAnimationStyle(R.style.popwindow_bottom_anim_style);
        // 实例化一个ColorDrawable颜色为半透明
        ColorDrawable popupWindowGB = new ColorDrawable(Color.parseColor("#95000000"));
        DeleteNoticepopupWindow.setBackgroundDrawable(popupWindowGB);
        // 在底部显示
        DeleteNoticepopupWindow.showAtLocation(mBodyView, Gravity.BOTTOM, 0, 0);

        //触摸监听
        tv_delete_ok.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                showDialog();
                removeBooks();
                recordBookDeleete(bookSet.size());
                dismissDialog();
                DeleteNoticepopupWindow.dismiss();
                if(isLongPressDelete){
                    MobclickAgent.onEvent(mContext, "bookshelf_long_delete");
                }
            }
        });

        tv_delete_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (isLongPressDelete) {
                    bookSet.clear();
                }
                DeleteNoticepopupWindow.dismiss();
            }
        });

        contentView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (isLongPressDelete) {
                    bookSet.clear();
                }
                DeleteNoticepopupWindow.dismiss();
            }
        });
    }

    /**
     * 网络连接时，刷新书架签到状态
     */
    private class NetConnectReceiver extends BroadcastReceiver{

        @Override
        public void onReceive(Context context, Intent intent) {
            if(intent != null && intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)){
                if (SystemUtil.isLogin()) {
//                    SigninRequester.requestData(mContext, SigninRequester.SIGNIN_REQUEST_BOOKSHELF);
                }
            }
        }
    }
}